import rsa

def generate_ca_puk_privk():
    pubk, prik = rsa.newkeys(512)
    publickey = pubk.save_pkcs1('PEM').decode('utf-8')
    privatekey = prik.save_pkcs1('PEM').decode('utf-8')
    with open('private.pem', 'w') as f:
        f.write(privatekey)
        f.close()
    with open('publickey.pem', 'w') as f:
        f.write(publickey)
        f.close()

generate_ca_puk_privk()